package one.to.many.bidir.un.un;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

public class OneToManyBidirUnUn {

	private static EntityManagerFactory emf;
	private static EntityManager em;
	private static EntityTransaction tx;

//	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
		
		System.out.println("OneToManyBidirUnUn.setUpBeforeClass()");
		
		emf = Persistence.createEntityManagerFactory("ophidia");
		em = emf.createEntityManager();
		tx = em.getTransaction();
	}

//	@AfterClass
	public static void tearDownAfterClass() throws Exception {
		
		System.out.println("OneToManyBidirUnUn.tearDownAfterClass()");
		
		em.close();
		emf.close();
	}

//	@Before
	public void setUp() throws Exception {
		
		System.out.println("OneToManyBidirUnUn.setUp()");
		
		tx.begin();
	}

//	@After
	public void tearDown() throws Exception {
		
		System.out.println("OneToManyBidirUnUn.tearDown()");
		
		tx.commit();
	}

//	@Test
	public void AaaaaTest() {
		System.out.println("OneToManyBidirUnUn.test()");
		E1 e1 = new E1("e12-1");
		Set<E2> e2s = new HashSet<E2>();
		e2s.add(new E2("e22-1", e1));
		e2s.add(new E2("e22-2", e1));
		e1.setE2s(e2s);
		em.persist(e1);
		
//		Set<E2> e2s = new HashSet<E2>();
//		e2s.add(new E2(e22, e1))
//		String e12 = "e12-1";
		
	}
}
